import React, { Fragment } from 'react';
import { Route, Switch } from 'react-router-dom';
import _ from 'lodash';

export default function RouterCell(props) {
    if (!_.get(props, ['children'])) {
        return (<Route {...props} />);
    } else {
        return (<Route path={props.path} render={() => {
            return (
                <Fragment>
                    <Switch>
                        {
                            _.get(props, ['children']) && _.get(props, ['children']).map((children, index) => {
                                return <Route key={`${children.path}${index + 1}`} {...children} />
                            })}
                    </Switch>
                </Fragment>
                )}}
         />)
    }
}
